zIndex = 500

W.showDialog = (content)->
    dialog = {}
    zIndex++
    $modal = $('<div>', class: 'dialog-modal').css(zIndex: zIndex).appendTo($('body'))
    dialog.$modal = $modal
    $dialog = $('<div>', class: 'dialog').appendTo($modal)
    $mask = $('<div>', class: 'mask').appendTo($modal)
    $dialog.append content

    dialogTop = (window.innerHeight - $modal.offset().top - $dialog.height()) * 0.3

    $dialog.css
        top: dialogTop + 'px'

    $('body').scrollTop(0)

    dialog.close = ->
        $modal.trigger('close')
        $modal.remove()

    $mask.on 'click', (e)->
        e.preventDefault()
        dialog.close()

    return dialog